﻿using Shake.Framework.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Shake.Web
{
    public class AreaConfig
    {
        public static void RegisterAreas(RouteCollection routes)
        {
            var assemblies = FeatureUtil.GetFeatureAssembly();
            foreach (var assembly in assemblies)
            {
                var areaRegistration = assembly.ExportedTypes.Where(t => t.BaseType == typeof(AreaRegistration)).ToList().FirstOrDefault();
                if (areaRegistration == null) continue;
                var area = areaRegistration.Assembly.CreateInstance(areaRegistration.FullName) as AreaRegistration;
                var areaContext = new AreaRegistrationContext(area.AreaName, routes);
                area.RegisterArea(areaContext);
            }
        }
    }
}